package com.breeze.blockchain.controller.admin.vo;

import com.breeze.blockchain.common.enums.PermissionResourceType;
import com.breeze.blockchain.mybatis.entity.PermissionDo;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.Data;

/**
 * @author breeze
 */
@Data
@Schema(name = "用户所有权限")
public class PermissionResourceVO {

  @Schema(title = "菜单")
  List<PermissionDo> menus;

  @Schema(title = "按钮")
  List<PermissionDo> buttons;

  public PermissionResourceVO fullData(Map<Integer, List<PermissionDo>> collect) {
    var menus =
        Stream.concat(
                collect
                    .getOrDefault(
                        PermissionResourceType.FRONT_MENU.getCode(), Collections.emptyList())
                    .stream(),
                collect
                    .getOrDefault(
                        PermissionResourceType.BACK_URL.getCode(), Collections.emptyList())
                    .stream())
            .collect(Collectors.toList());
    // 菜单
    this.setMenus(menus);
    // 按钮
    this.setButtons(
        collect.getOrDefault(
            PermissionResourceType.FRONT_BUTTON.getCode(), Collections.emptyList()));
    return this;
  }
}
